package com.ncmmall.application.business.cloudstore;

import com.ncmmall.domain.business.cloudstore.CloudStoreGoods;
import com.ncmmall.domain.business.cloudstore.CloudStoreGoodsRelevance;
import com.ncmmall.domain.business.cloudstore.CloudStoreGoodsRelevanceRepository;
import com.ncmmall.domain.business.goods.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author linxs
 * @Description: 云仓业务
 * @Date: 2020-05-24 15:29
 */
@Service
@Transactional
public class CloudStoreApplication {

    @Autowired
    private CloudStoreGoodsRelevanceRepository relevanceRepository;


    /**
     * 一键关联
     *
     * @param cloudStoreGoods
     * @param goodses
     */
    public void relevance(CloudStoreGoods cloudStoreGoods, List<Goods> goodses) {
        for (Goods goodse : goodses) {
            CloudStoreGoodsRelevance relevance = new CloudStoreGoodsRelevance();
            relevance.setGoods(goodse);
            relevance.setCloudStoreGoods(cloudStoreGoods);
            relevance.setMerchant(cloudStoreGoods.getMerchant());
            relevance.setSupplier(cloudStoreGoods.getSupplier());
            relevanceRepository.save(relevance);
        }
    }


}
